package cn.edu.ujs.coor.repository.project;

import cn.edu.ujs.coor.model.Project;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 项目Repository
 *
 * @author 柳曾雄
 * @date 2018-07-31
 */
@Repository
public interface ProjectRepository extends JpaRepository<Project, String>, JpaSpecificationExecutor<Project> {

    /**
     * 查询即将到期协同项目
     * @param diff
     * @return
     */
    @Query(value = "select * from coor_project where deadline - curdate() = ?1 and status = '0'", nativeQuery = true)
    List<Project> findNearDeadline (Integer diff);

    /**
     * 查询已到期协同项目
     * @return
     */
    @Query(value = "select * from coor_project where deadline - curdate() < 0 and status = '0'", nativeQuery = true)
    List<Project> findDeadlined ();
}
